Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

439
Visualizações
Multiple Checkbox - Change Message "Please check this box if you want to proceed"

I have a multiselect checkbox form to which I add a JS to make sure the visitor selects at least one option

<div class="form-group options">
<label class="control-label col-md-4" for="optiontext">Specify an option</label>
<div class="col-md-6">
    <input type="checkbox" name="option[]" value="option1" required/> Option 1<br>
    <input type="checkbox" name="option[]" value="option2" required/> Option 2<br>
    <input type="checkbox" name="option[]" value="option3" required/> Option 3<br>
    <input type="checkbox" name="option[]" value="option4" required/> Option 4<br>
    <input type="checkbox" name="option[]" value="option5" required/> Option 5<br>
    <input type="checkbox" name="option[]" value="option6" required/> Option 6<br>
    <input type="checkbox" name="option[]" value="option7" required/>  Option 7
</div>

That's the JS

$(function(){
var requiredCheckboxes = $('.options :checkbox[required]');
requiredCheckboxes.change(function(){
    if(requiredCheckboxes.is(':checked')) {
        requiredCheckboxes.removeAttr('required');
    } else {
        requiredCheckboxes.attr('required', 'required');
    }
});

Now ALL IS WORKING fine, the only thing is that the error message that comes up is Please check this box if you want to proceed but I would like the message to be Please select at least one option to proceed like illustrated on the picture here.

enter image description here

How do I go about it?

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It's very simple to control custom messages with the help of HTML5 event oninvalid

Code:

<input type="checkbox" value="option1"
   oninvalid="this.setCustomValidity('Please select at least one option to proceed')">
about 4 years ago · Santiago Trujillo Relatório

0

I implemented this as follows:

    <html>
    <head>
        <title>test</title>
    </head>
    <body>
        <form>
            <input type="checkbox" id="sterms" value="Agreed-to-Terms" onclick ="if (!this.checked) {this.setCustomValidity('برای ادامه لطفا این گزینه را تیک بزنید.');} else {this.setCustomValidity('');}" required>
                                <a href="privacy-policy.html">قوانین و شرایط استفاده را می پذیرم.</a>
            <button type="submit" class="form-control-submit-button">انجام آزمایش</button>
        </form>
        <script type="text/javascript">
            document.getElementById("sterms").setCustomValidity('برای ادامه لطفا این گزینه را تیک بزنید.');
        </script>
    </body>
</html>
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda